/**
 * @author 陈泰来
 * @version V1.0
 * @Project echo-java-base
 * @Title 互相引用GC回收测试
 * @Description *
 * @Package jvm.exception
 * @date 2021/3/25 3:13 下午
 * @Copyright:学如逆水行舟，不进则退 .
 */
package jvm.exception;

import java.util.Objects;

public class ReferenceCountingGC {

    private ReferenceCountingGC instance = null;


    /**
     * @Description 1MB大小
     * @Author chentl
     * @Create: 2021/3/25 3:13 下午
     */
    private static final int _1MB = 1024 * 1024;

    private final byte[] SMT = new byte[10 * _1MB];

    public static void main(String[] args) {
        ReferenceCountingGC objA = new ReferenceCountingGC();
        ReferenceCountingGC objB = new ReferenceCountingGC();

        //互相引用
        objA.instance = objB;
        objB.instance = objA;

        objA = null;
        objB = null;

        System.gc();
        //查看回收日志 ： 新生代回收至 0k ；老年代两个 10MB左右的对象被回收，剩余空间为389KB
//[GC (System.gc()) [PSYoungGen: 12215K->624K(18432K)] 22455K->10872K(38912K), 0.0011361 secs] [Times: user=0.01 sys=0.01, real=0.00 secs]
//[Full GC (System.gc()) [PSYoungGen: 624K->0K(18432K)] [ParOldGen: 10248K->389K(20480K)] 10872K->389K(38912K), [Metaspace: 3174K->3174K(1056768K)], 0.0034820 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
//        Heap
//        PSYoungGen      total 18432K, used 164K [0x00000007bec00000, 0x00000007c0000000, 0x00000007c0000000)
//        eden space 16384K, 1% used [0x00000007bec00000,0x00000007bec290d0,0x00000007bfc00000)
//        from space 2048K, 0% used [0x00000007bfc00000,0x00000007bfc00000,0x00000007bfe00000)
//        to   space 2048K, 0% used [0x00000007bfe00000,0x00000007bfe00000,0x00000007c0000000)
//        ParOldGen       total 20480K, used 389K [0x00000007bd800000, 0x00000007bec00000, 0x00000007bec00000)
//        object space 20480K, 1% used [0x00000007bd800000,0x00000007bd861448,0x00000007bec00000)
//        Metaspace       used 3181K, capacity 4496K, committed 4864K, reserved 1056768K
//        class space    used 353K, capacity 388K, committed 512K, reserved 1048576K


    }

}
